package com.xing.model.策略;

/**
 * 策略模式
 *  组合优于继承
 *  封装变化
 *  面对接口编程
 */
public abstract class Duck {

    protected  FlyBehavior flyBehavior;

    protected  QuackBehavior quackBehavior;

    public abstract void display();

    public void swim() {
        System.out.println("I can swim");
    }

    public void fly() {
        flyBehavior.fly();
    }

    public void quack() {
        quackBehavior.quack();
    }

    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
    }

    public  void setQuackBehavior(QuackBehavior quackBehavior) {
        this.quackBehavior = quackBehavior;
    }

}
